using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace HRM.Models.Mapping
{
    public class NhanVienMap : EntityTypeConfiguration<NhanVien>
    {
        public NhanVienMap()
        {
            // Primary Key
            this.HasKey(t => t.MaNV);

            // Properties
            this.Property(t => t.MaNV)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.HoTen)
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .HasMaxLength(20);

            this.Property(t => t.TenTK)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.MatKhau)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.MaDV)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.MaNNDung)
                .IsRequired()
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("NhanVien");
            this.Property(t => t.MaNV).HasColumnName("MaNV");
            this.Property(t => t.HoTen).HasColumnName("HoTen");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.TenTK).HasColumnName("TenTK");
            this.Property(t => t.MatKhau).HasColumnName("MatKhau");
            this.Property(t => t.MaDV).HasColumnName("MaDV");
            this.Property(t => t.MaNNDung).HasColumnName("MaNNDung");

            // Relationships
            this.HasRequired(t => t.DonVi)
                .WithMany(t => t.NhanViens)
                .HasForeignKey(d => d.MaDV);
            this.HasRequired(t => t.NhomNguoiDung)
                .WithMany(t => t.NhanViens)
                .HasForeignKey(d => d.MaNNDung);

        }
    }
}
